<template>
    <view style="height: 100%">
        <ul class="pd015 db">
            <block v-for="(item, index) in list" :key="index">
                <li class="pd150 bbf1 db">
                    <view class="df">
                        <image class="img40 br50 mr12"  referrerPolicy='no-referrer' :src="item.avatar" />
                        <view class="f1">
                            <p class="f14 c28 f600 db">{{ item.username }}</p>
                            <span class="f12 c9d db mt2">{{ item.created_at }}</span>
                        </view>
                    </view>
                    <p class="db f14 c28 mt12">{{ item.content }}</p>
                </li>
            </block>
        </ul>
    </view>
</template>

<script>
const http = require('../../utils/http');
export default {
    data() {
        return {
            page: 1,
            pageSize: 10,
            id: '',
            list: [],
            pageTotal: ''
        };
    },
    onLoad(options) {
        this.setData({
            id: options.id
        });
        this.getList();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        if (this.pageTotal > this.page) {
            this.setData({
                page: this.page + 1
            });
            this.getList();
        } else {
            uni.showToast({
                title: '没有更多啦~',
                icon: 'none'
            });
        }
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        getList() {
            let data = {
                page: this.page,
                pageSize: this.pageSize,
                goods_id: this.id
            };
            http.request('goods/commentList', data).then((res) => {
                res.data.list.forEach((i) => {
                    this.list.push(i);
                });
                this.setData({
                    list: this.list,
                    pageTotal: res.data.pageTotal
                });
            });
        }
    }
};
</script>
<style>
@import './comment.css';
</style>
